<?php
// +----------------------------------------------------------------------
// | Author: ZYN Fl
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
class Orders extends Common
{
    public function index()
    {   
        
		if(input('omobile'))
		{
			$where['omobile']=input('omobile');
		}
		if(input('ostarts')>='0')
		{
			$where['ostarts']=input('ostarts');
		}
        if(!empty($where)){
			
            $orders=Db::table('xcx_orders')->where($where)->order('oid desc')->paginate(8);
			$data=$orders->toArray();
			ifExist($data['data']);
	  }else{  
	  
            $orders=Db::table('xcx_orders')->order('oid desc')->paginate(8);
        
		}
		
        $page = $orders->render();
        $this->assign("orders",$orders);
		
        $this->assign('a','Orders');
        $this->assign('page', $page);
        return $this->fetch();
    }
    public function addlist()
    {
        $this->assign('a','Orders');
        return $this->fetch();
    }
    public function addxinx(){
        $bname = input('bname');
        $data = array(
            'bname' => $bname,
            'btime' => time()
            );
        $orders=Db::name('orders')->insert($data);
        if($orders){
            return 1;
        }
    }
    //编辑信息
    public function update()
    {
        $oid = input('oid');
        
        $data=Db::table('xcx_orders')->where("oid='$oid'")->find();
		$ogoods = explode(',',trim($data['ogoods'],','));
		
        $where['did'] = array('in',$ogoods);
        $goodslist=Db::name('ordergoods')->where($where)->select();
		
		$this->assign('a','Orders');
        $this->assign('goodslist',$goodslist);
        $this->assign("data",$data);
        return $this->fetch();
    }
    //保存信息
    public function xiugai(){
        $bid = input('bid');
        $bname = input('bname');
        $data = array(
            'bid' => $bid,
            'bname' => $bname,
            'btime' => time()
            );
        $orders=Db::name('orders')->where("bid='$bid'")->update($data);
        if($orders){
            return 1;
        }
        }
    //删除
    public function del(){
        $oid = input('oid');
        $data = array(
            'oid' =>$oid
            );
        $del=Db::name('orders')->where("oid='$oid'")->delete($data);
        if($del){
            return 1;
        }
    }
	//发货
	public function sendOrder()
	{	
		$oid=input("oid");
		if($oid)
		{
			$data['ostarts']=2;
			$save=Db::name('orders')->where("oid=".$oid)->update($data);
			
			if($save)
			{
				return 1;
			}else{
				return 2;
			}
		}
	}
}